/* eslint-disable camelcase */
// 引入api请求方法
import { getMenu } from '@/assets/js/api'
import { formatDate } from "@/utils/date"

const state = {
    // 接口调用参数
    postParams: {
        startRange: {
            // 开票时间开始
            startDate: formatDate(new Date().getTime() - 3600 * 1000 * 24, "yyyy-MM-dd"),
            // 开票时间结束
            endDate: formatDate(new Date().getTime() - 3600 * 1000 * 24, "yyyy-MM-dd"),
        },
        endRange: {
            // 开票时间开始
            startDate: "0000-00-00",
            // 开票时间结束
            endDate: "0000-00-00",
        },
        pageTabs: ["核心看板"],
        page: 1,
        dateType: 'date',
        condition:""
    },
    // 统计data数据
    staticticsData: null,
}

// getters
const getters = {}

// actions
const actions = {
    // 获取列表数据
    getList: async (context) => {
        let params = {
            ...context.state.postParams,
            startDate: context.state.postParams.startDate ? new Date(context.state.postParams.startDate + " 00:00:00").getTime() : "",
            endDate: context.state.postParams.endDate ? new Date(context.state.postParams.endDate + " 23:59:59").getTime() : ""
        }
        let { data } = await getMenu(params)
        console.log(data, "month");
        context.commit('updateStaticticsData', Object.assign({}, context.state.staticticsData, data));
    }
}

// mutations
const mutations = {
    // 更新data数据
    updateStaticticsData (state, payload) {
        state.staticticsData = payload
    },
    // 更新列表参数数据
    updatePostParams (state, payload) {
        state.postParams = Object.assign({}, state.postParams, payload)
    },
}

export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
